const baseUrl = 'https://springboot-m195-186985-9-1378969143.sh.run.tcloudbase.com'; // 替换为你的后端服务地址

// 通用请求方法
function request(url, method, data) {
  return new Promise((resolve, reject) => {
    wx.request({
      url: baseUrl + url,
      method: method,
      data: data,
      header: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${wx.getStorageSync('token')}`
      },
      success: (res) => {
        if (res.statusCode === 200) {
          resolve(res.data);
        } else {
          reject(res.data);
        }
      },
      fail: (err) => {
        reject(err);
      }
    });
  });
}

// 获取签到状态
function getCheckinStatus() {
  return request('/api/checkin/status', 'GET');
}

// 签到
function checkin() {
  return request('/api/checkin', 'POST');
}

// 获取每日任务
function getDailyTasks() {
  return request('/api/tasks/daily', 'GET');
}

// 完成任务
function completeTask(taskId) {
  return request('/api/tasks/complete', 'POST', { taskId });
}

// 检查成就
function checkAchievements() {
  return request('/api/achievements/check', 'GET');
}

module.exports = {
  getCheckinStatus,
  checkin,
  getDailyTasks,
  completeTask,
  checkAchievements
};